package com.kjtpay.design_pattern.template_method;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.kjtpay.design_pattern.R;
import com.kjtpay.design_pattern.prototype.PrototypeActivity;

public class TemplateMethodActivity extends AppCompatActivity {

    public static void launch(Context context) {
        if (null != context) {
            Intent intent = new Intent();
            intent.setClass(context, TemplateMethodActivity.class);
            if (!(context instanceof Activity)) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            }
            context.startActivity(intent);
        }
    }

    TextView testPaperTextView;
    TestPaperA studentA;
    TestPaperB studentB;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_template_method);
        setTitle("模板方法模式");

        testPaperTextView = findViewById(R.id.textViewTestPaper);
        studentA = new TestPaperA();
        studentB = new TestPaperB();
    }

    public void onStudentAClick(View view) {
        testPaperTextView.setText(studentA.display());
    }

    public void onStudentBClick(View view) {
        testPaperTextView.setText(studentB.display());
    }
}